package com.wn.pianTai.controller;


import com.wn.dal.entity.Booktype;
import com.wn.serviceLa.service.BooktypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wnlqy
 * @since 2023-04-26 12:10:21
 */
@RestController
@RequestMapping("/booktype")
public class BooktypeController {

    @Autowired
    BooktypeService booktypeService;

    @Autowired
    RedisTemplate<String,Object> stringObjectRedisTemplate;


    @RequestMapping("/queryAll")
    public List<Booktype> query(){
        ValueOperations<String, Object> opsForValue = stringObjectRedisTemplate.opsForValue();
        Object bookShopType = opsForValue.get("bookShopType");
        List<Booktype> list = null;
        if(bookShopType == null){
            list = booktypeService.list();
            opsForValue.set("bookShopType",list);
        }else {
            list = (List<Booktype>) bookShopType;
        }
        return list;
    }

}

